package 剑指;

public class offer29 {
    public int[] spiralOrder(int[][] matrix) {
        int[] arr = new int[matrix.length*matrix[0].length];
        boolean flg = true;
        int index=0;
        for (int i = 0; i < matrix.length && flg; i++) {
            if(flg) {
                int j = 0;
                while (j < matrix[0].length) {
                    arr[index++] = matrix[i][j];
                    j++;
                }
            }else {
                int j = matrix[0].length;
                while (j >= 0) {
                    arr[index++] = matrix[i][j];
                    j--;
                }
            }
            flg = !flg;
        }
        return arr;
    }
}
